﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using STMS.BLL;

namespace STMS.STMSApp
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 登录按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uCircleButton1_Click(object sender, EventArgs e)
        {
            //接收页面输入
            string uName = textBox_userName.Text.Trim();
            string uPwd = textBox_password.Text.Trim();
            //检查信息  ---非空检查
            if (string.IsNullOrEmpty(uName))
            {
                MessageBox.Show("请输入账号");
            }
            else if (string.IsNullOrEmpty(uPwd))
            {
                MessageBox.Show("请输入密码");
            }
            //登录过程---检查用户的存在性
            UserBLL userBLL = new UserBLL();
            if(userBLL.LoginSystem(uName, uPwd))
            {
                //检查结果，作处理：存在  ---成功，显示主页面；不存在，中断
                MainForm mainForm = new MainForm();
                mainForm.Tag = uName;
                mainForm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("账号或密码输入不正确，请重新输入","提示");
            }


        }

        //初始化退出系统按钮
        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("是否退出系统?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Application.ExitThread();
            }else
                e.Cancel = true;
        }

    }
}
